package cn.tkb.order.controller;

import cn.tkb.basic.util.AjaxResult;
import cn.tkb.basic.util.LoginContext;
import cn.tkb.basic.util.PageQuery;
import cn.tkb.order.domain.AdoptOrder;
import cn.tkb.order.query.AdoptOrderQuery;
import cn.tkb.order.service.IAdoptOrderService;
import cn.tkb.order.service.IProductOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/adopt")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;
    @PostMapping()
    public AjaxResult adopt(@RequestBody Map<String,Object> params, HttpServletRequest request){
        try{
            //这里返回支付字符串，作用是什么？？  明天知道
            String payData = adoptOrderService.adopt(params, LoginContext.getCurrentLoginInfo(request));
            System.out.println(payData);
            return AjaxResult.success().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.fail("下单失败！"+e.getMessage());
        }
    }

    /**
     * 用户查询自己的领养订单
     * @param query
     * @param request
     * @return
     */
    @PostMapping("/user")
    public PageQuery<AdoptOrder> user(@RequestBody AdoptOrderQuery query,HttpServletRequest request){
        return adoptOrderService.user(query,LoginContext.getCurrentLoginInfo(request));
    }

    /**
     * 平台管理员或者店铺管理员查询领养订单
     * @param query
     * @param request
     * @return
     */
    @PostMapping("/admin")
    public PageQuery<AdoptOrder> admin(@RequestBody AdoptOrderQuery query,HttpServletRequest request){
       return adoptOrderService.admin(query,LoginContext.getCurrentLoginInfo(request));
    }
}
